# time_model.py
import datetime
from PySide6.QtCore import QObject, Q_PROPERTY, QTimer, QDateTime

class TimeModel(QObject):
    def __init__(self):
        super().__init__()
        self.timer = QTimer()
        self.timer.timeout.connect(self.update_time)
        self.is_running = False

    @Q_PROPERTY(bool READ is_running WRITE set_running NOTIFY running_changed)
    def is_running_(self):
        return self.is_running

    def set_running(self, value):
        if self.is_running != value:
            self.is_running = value
            if value:
                self.timer.start(1000)  # 每秒更新一次
            else:
                self.timer.stop()
            self.running_changed.emit()

    running_changed = QtCore.Signal()

    def update_time(self):
        self.currentTime = QDateTime.currentDateTime().toString("yyyy-MM-dd HH:mm:ss")

